package org.breathe.command.impl.personal;

import lombok.extern.slf4j.Slf4j;
import org.breathe.command.Command;
import org.breathe.command.CommandType;
import org.breathe.datastruct.RedisBytes;
import org.breathe.datastruct.RedisData;
import org.breathe.protocal.Resp;
import org.breathe.protocal.decode.BulkString;
import org.breathe.protocal.decode.Errors;
import org.breathe.server.core.RedisCore;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: breathe
 * @createTime: 2025-05-13
 */
@Slf4j
public class Breathe implements Command {
    private RedisCore redisCore;
    private RedisBytes key;
    private List<String> names;
    private String allPeople = "";

    public Breathe(RedisCore redisCore) {
        this.redisCore = redisCore;
    }
    @Override
    public CommandType getType() {
        return CommandType.BREATHE;
    }

    @Override
    public void setContext(Resp[] array) {
        names = Arrays.stream(array)
                .skip(1)
                .map(each -> ((BulkString)each).getContent().getString())
                .collect(Collectors.toList());
    }

    @Override
    public Resp handle() {
        names.forEach(each -> {
            allPeople += each + ",";
        });
        return new BulkString(("breathe is our god." + (allPeople != null && !allPeople.isEmpty() ? allPeople.substring(0, allPeople.length() - 1) + " must to worship him" : "")).getBytes());
    }

    @Override
    public boolean writeCommand() {
        return false;
    }
}
